﻿using System.Text.RegularExpressions;

namespace HuaCheng.Controller
{
    
    public class Util
    {
        /// <summary>
        /// 验证邮箱格式
        /// </summary>
        /// <param name="email"></param>
        /// <returns></returns>
        public static bool IsEmail(string email)
        {
            bool EmailFlag = false;
            //Regex re = new Regex(@"[\w!#$%&'*+/=?^_`{|}~-]+(?:\.[\w!#$%&'*+/=?^_`{|}~-]+)*@(?:[\w](?:[\w-]*[\w])?\.)+[\w](?:[\w-]*[\w])?");//实例化一个Regex对象
            Regex re = new Regex("^\\s*([A-Za-z0-9_-]+(\\.\\w+)*@(\\w+\\.)+\\w{2,5})\\s*$");
            if (re.IsMatch(email) == true)//验证数据是否匹配
            {
                EmailFlag = true;
            }
            return EmailFlag;
        }
        /// <summary>
        /// 验证是否是电池条码
        /// </summary>
        /// <param name="barcode"></param>
        /// <returns></returns>
        public static bool IsBatBarcode(string barcode)
        {
            bool flag = false;
            Regex re = new Regex("^[A-Za-z0-9]{10}\\d{2}$");//实例化一个Regex对象
            if (re.IsMatch(barcode) == true)//验证数据是否匹配
            {
                flag = true;
            }
            return flag;
        }
        /// <summary>
        /// 验证是否是序号
        /// </summary>
        /// <param name="endNum"></param>
        /// <returns></returns>
        public static bool IsBatNum(string endNum)
        {
            bool flag = false;
            Regex re = new Regex(@"[A-Za-z0-9]{1,2}$");//实例化一个Regex对象
            if (re.IsMatch(endNum) == true)//验证数据是否匹配
            {
                flag = true;
            }
            return flag;
        }
    }
}
